import 'package:flutter/material.dart';
import 'package:flutter_aliyun_captcha/flutter_aliyun_captcha.dart';
import 'package:intl/intl.dart';
import 'package:flutter_syt/application.dart';
import 'package:flutter_syt/utils/utils_dlog.dart';
//  FFFF0N0000000000AF6C ic_register_h5 智能验证 H5 注册
//  FFFF0N0000000000AF6C ic_login_h5  智能验证 H5 登录
//  FFFF0N0000000000AF6C ic_message_h5   智能验证 H5  短信

enum DytAliyunStatus {
  DytAliyunStatusLogin, // 登录
  DytAliyunStatusRegister, // 注册
  DytAliyunStatusMessage, // 短信
}

class DytAliyunWidget extends StatelessWidget {
  final AliyunCaptchaController? controller;
  // final String scene;
  final DytAliyunStatus status;
  final Function(dynamic data)? onSuccess;
  final Function(String failCode)? onFailure;
  final Function(String errorCode)? onError;
  DytAliyunWidget(
      {required this.status,
      this.controller,
      this.onSuccess,
      this.onError,
      this.onFailure});
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 68,
      margin: EdgeInsets.symmetric(vertical: 10),
      child: AliyunCaptchaButton(
        controller: controller,
        type: AliyunCaptchaType.smart,
        option: AliyunCaptchaOption(
          appKey: 'FFFF0N0000000000AF6C',
          scene: status == DytAliyunStatus.DytAliyunStatusLogin
              ? "ic_login_h5"
              : status == DytAliyunStatus.DytAliyunStatusRegister
                  ? "ic_register_h5"
                  : "ic_message_h5",
          language: (appContext.storage.getString("storyLocal") ??
                      Intl.getCurrentLocale()) ==
                  'zh'
              ? 'cn'
              : 'en',
        ),
        onSuccess: (dynamic data) {
          DLog('onSuccess' + data.toString());
          if (onSuccess != null) {
            onSuccess!(data);
            Navigator.pop(context);
          }
        },
        onFailure: (String failCode) {
          DLog('onFailure' + 'failCode: $failCode');
          if (onFailure != null) {
            onFailure!(failCode);
          }
        },
        onError: (String errorCode) {
          DLog('onError' + 'errorCode: $errorCode');
          if (onError != null) {
            onError!(errorCode);
          }
        },
      ),
    );
  }
}
